package im.dhc.gitdiff.common;

import im.dhc.gitdiff.util.PathUtil;

import java.io.BufferedWriter;
import java.io.IOException;

/**
 * @author songhaichao
 * @create 2020-06-09-11:18
 **/
public class DeleteDiffHandler extends AbstractDiffHandler{

    public DeleteDiffHandler(String oldPath, String newPath, BufferedWriter backupbw, BufferedWriter updatebw, BufferedWriter recoverbw) throws Exception {
        super(oldPath,newPath,backupbw,updatebw,recoverbw);
        if(PathUtil.isJavaFile(oldPath)){
            this.newPath = this.oldPath;
        }
    }

    public void backupHandle() throws IOException {
        backupbw.write(backUp());
        backupbw.newLine();
    }

    public void updateHandle() throws IOException {
        if(PathUtil.isJarFile(this.oldPath)){
            updatebw.write(this.update());
        }else{
            updatebw.write(delete(this.oldPath));
        }
        updatebw.newLine();

    }

    public void recoverHandle() throws IOException {
        recoverbw.write(recover());
        recoverbw.newLine();
    }

    public void copyFileHandle() throws IOException {
        return;
    }
}
